package com.five.welcome.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.welcome.entity.Studentinfo;
import com.five.welcome.result.Result;
import com.five.welcome.service.StudentinfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@CrossOrigin
@Tag(name = "学生信息接口")
@RestController
@RequestMapping("/studentinfo")
public class StudentinfoController {

    @Autowired
    private StudentinfoService studentinfoService;

    //注册学生信息
    @Operation(summary = "注册学生信息")
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody Studentinfo studentinfo) {
        int s = studentinfoService.addStudent(studentinfo);
        if (s > 0) {
            return Result.ok();
        }
        return Result.error("注册失败!");
    }

    //根据学号查询学生信息
    @Operation(summary = "根据学号查询学生信息")
    @GetMapping("/getInfoBySNumber")
    public Result getInfoBySNumber(String sNumber) {
        Studentinfo studentinfo = studentinfoService.getInfoBySNumber(sNumber);
        if (studentinfo != null) {
            return Result.ok(studentinfo);
        }
        return Result.error("暂未查到您的信息!");
    }

    //分页查询学生信息
    @Operation(summary = "分页条件查询")
    @GetMapping("/page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNumber,
                       @RequestParam(defaultValue = "2") Integer pageSize,
                       String sNumber,String major,String classes) {
        Page<Studentinfo> page = studentinfoService.myPage(pageNumber, pageSize,
                sNumber,major,classes);
        return Result.ok(page);
    }
}

